home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir41 / timstk11.zip / README3.TXT < prev    next >
Text File  |  1993-04-01  |  18KB  |  466 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.          T i m e S t a c k
  18.          The Ultimate Software Timing and Stack Analysis Utility
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.          Worst Case Timing And Stack Analysis Increases Quality and
  28.          Confidence
  29.  
  30.                    During the late 1600's Sir Isaac Newton revolutionized
  31.                    the scientific community with his laws of gravity and
  32.                    planetary motion. At the time, these laws appeared
  33.                    flawless.
  34.  
  35.                    However, as new discoveries came to light, it became
  36.                    apparent that Newton's laws did not work when pushed to
  37.                    their extremes. By the early 20th century, Albert
  38.                    Einstein had developed a new set of laws that worked
  39.                    even at the speed of light.
  40.  
  41.                    Many software programs suffer from the same malady.
  42.                    They work fine under normal conditions, but break down
  43.                    when pushed to the extreme.
  44.  
  45.  
  46.          How Many Errors
  47.  
  48.                    Many studies have been done to determine the number of
  49.                    defects in a software program. Figure 1 shows the
  50.                    results from the University of Maryland's Software
  51.                    Engineering Laboratory. They measured defects in
  52.                    software created at NASA's Goddard Space Center. While
  53.                    it is clear that quality is improving, it will never
  54.                    reach perfection.
  55.  
  56.  
  57.  
  58.  
  59.                                          1          TimeStack - The Software Timing and Stack Analysis Tool
  60.  
  61.  
  62.  
  63.                     Bugs, Errors, Defects
  64.                                                    X - Worst
  65.                       12 -|                        * - Average
  66.                           |   X                    O - Best
  67.                           |
  68.                       10 -|         X
  69.                           |               X
  70.                           |   *                 X
  71.                        8 -|         *
  72.                           |               *           X
  73.                           |   O                 *           X
  74.                        6 -|         O     O           *     *     X
  75.                           |                     O     O           *     X
  76.                           |                                 O     O    *O
  77.                        4 -|
  78.                           |
  79.                           |
  80.                        2 -|
  81.                           |
  82.                           |
  83.                        0 -+---+-----+-----+-----+-----+-----+-----+-----+-
  84.                               76    78    80    82    84    86    88    90
  85.                                                   Year
  86.  
  87.                    Figure 1  Number of bugs, Errors, Defects per 1,000
  88.                              Lines of Code
  89.  
  90.  
  91.                    Testing software is not easy.  It is not unusual to
  92.                    find that a program thoroughly tested by conventional
  93.                    methods still contains fatal flaws. AT&T learned the
  94.                    lesson the hard way on January 15, 1990. A slight
  95.                    software error disabled nearly half their long distance
  96.                    lines around the country for almost nine hours.
  97.  
  98.  
  99.          Error Sensitivity
  100.  
  101.                    Obviously software is extremely sensitive to small
  102.                    errors. Mechanical parts can accommodate a small
  103.                    variance. Unfortunately, computers only understand
  104.                    right or wrong; they cannot interpret gray areas. One
  105.                    tiny error can snowball into a disaster.
  106.  
  107.                    Sooner or later, every product is asked to perform at
  108.                    its limits. However uncommon the situation, when it
  109.                    happens, will your software meet the challenge?
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.                                          2          TimeStack - The Software Timing and Stack Analysis Tool
  118.  
  119.  
  120.  
  121.          What Can Go Wrong
  122.  
  123.                    For someone who writes complex software, it doesn't
  124.                    take much of an imagination to understand how many
  125.                    things can go wrong. And, depending upon the product
  126.                    the software controls, an error can cause a malfunction
  127.                    resulting in annoyance at the least or a disaster in
  128.                    critical situations.
  129.  
  130.                    Execution time is one area where errors can slip by
  131.                    until it's too late. A program may get some combination
  132.                    of inputs that cause it to run longer than its typical
  133.                    time. Then what? A critical task could get skipped or
  134.                    run out of order. Tasks could begin to nest and/or
  135.                    exhaust their stack space. The initial small error has
  136.                    become a huge problem.
  137.  
  138.                    Sometimes a programming or compiler error allows an
  139.                    imbalanced stack. Something could get put on the stack
  140.                    but not taken off. Once again, a huge problem can
  141.                    result from an initial small error.
  142.  
  143.  
  144.          The Solution
  145.  
  146.                    The answer to all of these questions is a TimeStack
  147.                    analysis.
  148.  
  149.                    This analysis will provide, in detail, for every
  150.                    function, the theoretical:
  151.  
  152.                    *    maximum execution time,
  153.  
  154.                    *    minimum execution time,
  155.  
  156.                    *    worst stack depth usage, and
  157.  
  158.                    *    possible stack imbalances.
  159.  
  160.  
  161.          Maximum Execution Time
  162.  
  163.                    The theoretical maximum execution time is found by
  164.                    looking at all possible combination of paths that a
  165.                    function can take. This is difficult at best to do by
  166.                    hand for small programs, almost impossible for programs
  167.                    of any significant size. In programs that must execute
  168.                    in a given time, this information is essential.
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.                                          3          TimeStack - The Software Timing and Stack Analysis Tool
  176.  
  177.  
  178.  
  179.          Minimum Execution Time
  180.  
  181.                    The quickest path through a function is also found.
  182.                    This is important if some processing must always take
  183.                    place. A too short execution time could indicate that a
  184.                    critical function is being skipped.
  185.  
  186.  
  187.          Worst Stack Depth
  188.  
  189.                    It is important to know how much stack a function uses.
  190.                    A typical amount may not be the same as its worst case.
  191.                    An overflowed stack usually means overwriting something
  192.                    important. Almost always the problem crops up at a
  193.                    distant point from the initial overflow and that makes
  194.                    it difficult to find.
  195.  
  196.  
  197.          Stack Imbalances
  198.  
  199.                    Most assembly language programmers have accidentally
  200.                    done this. A typical error would involve putting
  201.                    something on the stack and forgetting to take it off,
  202.                    or taking the wrong amount off.
  203.  
  204.                    A more subtle stack imbalance occurs when saving values
  205.                    in the midst of complex logic. With the use of
  206.                    conditional branches, the possibility arises of putting
  207.                    something on the stack, while a complex path bypasses
  208.                    its removal.
  209.  
  210.  
  211.          Number of Paths
  212.  
  213.                    Obviously, the more paths involved in a complex
  214.                    algorithm, the more possibility for error exists. A
  215.                    program with only one or two conditional branches is
  216.                    relatively easy to time and check. But, the possible
  217.                    number of paths rises exponentially with the addition
  218.                    of each conditional branch.
  219.  
  220.                    The worst case or maximum number of paths in a program
  221.                    increases by 2^n where 'n' is the number of conditional
  222.                    branches. The minimum number of paths is n + 1.
  223.  
  224.                    In the typical program, neither of these extremes are
  225.                    realistic. However, they do provide a set of
  226.                    boundaries. Figure 2 shows these limits graphed as a
  227.                    function of the number of conditional branches.
  228.  
  229.  
  230.  
  231.  
  232.  
  233.                                          4          TimeStack - The Software Timing and Stack Analysis Tool
  234.  
  235.  
  236.  
  237.                    Possible paths
  238.                                                            X - Worst
  239.                    100000 -|                     X         O - Best
  240.                            |
  241.                            |
  242.                     10000 -|                                           O
  243.                            |
  244.                            |
  245.                      1000 -|                   X               O
  246.                            |
  247.                            |
  248.                       100 -|                           O
  249.                            |                X
  250.                            |
  251.                        10 -|                   O
  252.                            |
  253.                            |           XO
  254.                         1 -+---XO------+-------+-------+-------+-------+-
  255.                                0       1       10     100     1000   10000
  256.                                     Number of conditional branches
  257.  
  258.                    Figure 2  Number of Paths vs. Number of Conditional
  259.                              Branches
  260.  
  261.  
  262.                    Most programs average a conditional branch every 10 to
  263.                    20 bytes. A small 100 byte function would thus have an
  264.                    average of least five conditional branches. That means
  265.                    just this simple procedure all by itself would have
  266.                    between six and 32 possible paths. Now imagine how many
  267.                    paths a 100K program must have!
  268.  
  269.  
  270.          How To Check
  271.  
  272.                    How do the engineers in your company time and check
  273.                    their programs? Have they ever been checked completely?
  274.                    Clearly, a program of any complexity quickly becomes
  275.                    almost impossible to check. Many times it becomes
  276.                    necessary to just cross your fingers and hope it works.
  277.                    The methods most commonly used simply cannot handle
  278.                    complex programs.
  279.  
  280.  
  281.          Impractical To Do It Manually
  282.  
  283.                    With the number of possible paths in a program of any
  284.                    complexity, it is apparent that hand counting the
  285.                    execution time is a near-impossible task. Even if one
  286.                    were to sit and methodically examine each possible
  287.                    path, the probability of missing one is tremendous. And
  288.  
  289.  
  290.  
  291.                                          5          TimeStack - The Software Timing and Stack Analysis Tool
  292.  
  293.  
  294.  
  295.                    of course, the time wasted on this endeavor could be
  296.                    much more efficiently used for other aspects of
  297.                    programming.
  298.  
  299.  
  300.          Logic Analyzers
  301.  
  302.                    It would seem that a logic analyzer could do the job.
  303.                    It would -- but only if the software executes in a
  304.                    simple linear fashion. As long as there are no
  305.                    decisions to be made that can change the direction of
  306.                    flow, it will work fine.
  307.  
  308.                    It becomes more complex if the timing depends upon the
  309.                    state of an input switch. Then you have to look at the
  310.                    switch in both positions. What if the timing depends on
  311.                    an interaction with a number of inputs? Or a calculated
  312.                    value? Using a logic analyzer quickly becomes
  313.                    cumbersome and is still unlikely to catch the absolute
  314.                    maximum path.
  315.  
  316.  
  317.          Simulators
  318.  
  319.                    A simulator relies upon user input to configure the
  320.                    simulator to try a finite number of branches. It will
  321.                    time the maximum execution time -- if you tell it which
  322.                    path that is. A simulator does not try every possible
  323.                    combination of execution paths looking for maximum and
  324.                    minimum execution times, deepest stack depth or stack
  325.                    imbalances.
  326.  
  327.                    Even if the simulator follows a test suite, tests
  328.                    inputs at their limits or does random combinations in
  329.                    between, that still does not guarantee it will find the
  330.                    answers to those nagging questions.
  331.  
  332.  
  333.          Profilers
  334.  
  335.                    A profiler is no better than a logic analyzer. Once
  336.                    again, it depends upon the user to determine the inputs
  337.                    and execution paths. You can never be sure the maximum
  338.                    path or stack has been found.
  339.  
  340.  
  341.          The Cost Of Failure
  342.  
  343.                    When a software program fails to carry out its
  344.                    appointed task, it is difficult to calculate the cost
  345.                    of failure. Deciding how to assess these costs is a
  346.  
  347.  
  348.  
  349.                                          6          TimeStack - The Software Timing and Stack Analysis Tool
  350.  
  351.  
  352.  
  353.                    decision each company must come to on its own. It has
  354.                    been mentioned because it is important when balancing
  355.                    the cost of testing with the cost of failure.
  356.  
  357.  
  358.          Slightly Pessimistic
  359.  
  360.                    A timing and stack analysis has one weakness: the
  361.                    results may be slightly pessimistic with some
  362.                    algorithms. This is typically caused by functions that
  363.                    are mutually exclusive but are timed together anyway.
  364.  
  365.                    Nevertheless, it would be nice to have that safe
  366.                    feeling that your program will perform even under
  367.                    unrealistic circumstances. And isn't it better to err
  368.                    on the conservative side?
  369.  
  370.  
  371.          Standards for Government Software Development
  372.  
  373.                    Government document DOD-STD-2167A relates to the
  374.                    acquisition, development, or support of software
  375.                    systems. In paragraph 4.2.1 it says "The contractor
  376.                    shall use systematic and well documented software
  377.                    development methods to perform ... testing of the
  378.                    deliverable software." Paragraph 5.4.2.5: "The
  379.                    contractor's ... testing shall include stressing the
  380.                    software at the limits of its specified requirements."
  381.  
  382.                    It would seem prudent to include a TimeStack analysis
  383.                    to know where those limits are.
  384.  
  385.  
  386.          Aviation Industry Guidelines
  387.  
  388.                    Manufactures of aviation products have devised a series
  389.                    of guidelines for their equipment. Document RTCA/DO-
  390.                    178A, titled "Software Considerations in Airborne
  391.                    Systems and Equipment Certification", proposes
  392.                    guidelines for software in avionics and flight critical
  393.                    functions.
  394.  
  395.                    For obvious reasons, design, verification, and testing
  396.                    are very important in this area. It mentions the
  397.                    importance of execution flow and timing, measuring CPU
  398.                    utilization, and software input transient load effects.
  399.  
  400.                    A TimeStack analysis is of great benefit to these types
  401.                    of programs.
  402.  
  403.  
  404.  
  405.  
  406.  
  407.                                          7          TimeStack - The Software Timing and Stack Analysis Tool
  408.  
  409.  
  410.  
  411.          Bibliography
  412.  
  413.                    F. W. Blakely and M. E. Boles, "A Case Study of Code
  414.                    Inspections," Hewlett-Packard Journal, Vol 42 no. 4,
  415.                    October 1991, pp. 58-63.
  416.  
  417.                    F. P. Brooks, Jr., "The Mythical Man-month," Addison-
  418.                    Wesley, 1975.
  419.  
  420.                    T. H. Cormen, C. E. Leiserson and R. L. Rivest,
  421.                    "Introduction to Algorithms," McGraw-Hill, 1990.
  422.  
  423.                    R. B. Grady and D. L. Caswell, "Software Metrics:
  424.                    Establishing a Company-wide Program," Prentice-Hall,
  425.                    1987.
  426.  
  427.                    L. Lee, "The Day The Phones Stopped," Donald I. Fine,
  428.                    Inc., 1991.
  429.  
  430.                    D. L. Parnas, A. J. van Schouwen, and S. P. Kwan,
  431.                    "Evaluation of Safety-Critical Software," Commun. ACM,
  432.                    Vol 33 no. 6, June 1990, pp. 636-648.
  433.  
  434.                    R. Resnick and D. Halliday, "Physics, Part I," John
  435.                    Wiley & Sons, Third edition, 1977.
  436.  
  437.                    E. I. Schwartz, "Turning Software From a Black Art into
  438.                    a Science," Business Week, October 25, 1991, pp. 80.
  439.  
  440.                    W. T. Ward, "Calculating the Real Cost of Software
  441.                    Defects," Hewlett-Packard Journal, Vol. 42 no. 4,
  442.                    October 1991, pp. 55-58.
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.                                          8
  466.